package com.hue.netty.day03.tcpprotocol;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/*
    服务端的处理器:需要继承ChannelInboundHandlerAdapter
 */
public class ServerHandler extends SimpleChannelInboundHandler<MessageProtocol> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, MessageProtocol msg) throws Exception {
        System.out.println("服务端接收到消息:");
        System.out.println("len="+msg.getLen());
        System.out.println("buffer="+new String(msg.getBuffer(),"UTF-8"));
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        ctx.close();
    }
}
